package cn.biplam.back.bean.ddl.sql2db;

import cn.biplam.back.bean.ddl.sql2db.field.FieldDb2;
import cn.biplam.back.bean.ddl.sql2db.field.FieldDerby;
import cn.biplam.back.bean.ddl.sql2db.field.FieldInformax;
import cn.biplam.back.bean.ddl.sql2db.field.FieldMysql;
import cn.biplam.back.bean.ddl.sql2db.field.FieldOracle;
import cn.biplam.back.bean.ddl.sql2db.field.FieldSqlServer;
import cn.biplam.back.bean.ddl.sql2db.field.FieldSybase;
import cn.biplam.back.bean.ddl.sql2db.fk.FkDb2;
import cn.biplam.back.bean.ddl.sql2db.fk.FkDerby;
import cn.biplam.back.bean.ddl.sql2db.fk.FkInformax;
import cn.biplam.back.bean.ddl.sql2db.fk.FkMySql;
import cn.biplam.back.bean.ddl.sql2db.fk.FkOracle;
import cn.biplam.back.bean.ddl.sql2db.fk.FkSqlServer;
import cn.biplam.back.bean.ddl.sql2db.fk.FkSybase;
import cn.biplam.back.bean.ddl.sql2db.index.IndexDb2;
import cn.biplam.back.bean.ddl.sql2db.index.IndexDerby;
import cn.biplam.back.bean.ddl.sql2db.index.IndexInformax;
import cn.biplam.back.bean.ddl.sql2db.index.IndexMySql;
import cn.biplam.back.bean.ddl.sql2db.index.IndexOracle;
import cn.biplam.back.bean.ddl.sql2db.index.IndexSqlServer;
import cn.biplam.back.bean.ddl.sql2db.index.IndexSybase;
import cn.biplam.back.bean.ddl.sql2db.pk.PkDb2;
import cn.biplam.back.bean.ddl.sql2db.pk.PkDerby;
import cn.biplam.back.bean.ddl.sql2db.pk.PkInformax;
import cn.biplam.back.bean.ddl.sql2db.pk.PkMySql;
import cn.biplam.back.bean.ddl.sql2db.pk.PkOracle;
import cn.biplam.back.bean.ddl.sql2db.pk.PkSqlServer;
import cn.biplam.back.bean.ddl.sql2db.pk.PkSybase;
import cn.biplam.back.sql.ddl.Table;
import cn.biplam.common.bean.sqlengine.Sql;
import cn.biplam.common.client.DbResource;
import cn.biplam.common.paramters.DatabaseType;
import cn.biplam.common.wrapper.ErrorMessage;

/**
 * sql2db的工厂类
 * @author WangSong 2009-8-4下午05:18:52
 * @version 1.0
 */
public class Sql2DbFactory {
	
	private Table table;
	private String dbType;
	
	public Sql2DbFactory(DbResource mDbResource,Table mTable){
		this.dbType = mDbResource.getDbtype();
		this.table = mTable;
	}
	
	/**
	 * 取建表sql
	 * @return 建表sql
	 * @throws ErrorMessage 
	 */
	public Sql getTable() throws ErrorMessage{
		if(DatabaseType.DataBase_Type.Oracle.toString().equals(dbType)){
			return new Sql(new FieldOracle().get(table));
		}else if(DatabaseType.DataBase_Type.Db2.toString().equals(dbType)){
			return new Sql(new FieldDb2().get(table));
		}else if(DatabaseType.DataBase_Type.Sybase.toString().equals(dbType)){
			return new Sql(new FieldSybase().get(table));
		}else if(DatabaseType.DataBase_Type.SqlServer.toString().equals(dbType)){
			return new Sql(new FieldSqlServer().get(table));
		}else if(DatabaseType.DataBase_Type.Informax.toString().equals(dbType)){
			return new Sql(new FieldInformax().get(table));
		}else if(DatabaseType.DataBase_Type.Derby.toString().equals(dbType)){
			return new Sql(new FieldDerby().get(table));
		}else if(DatabaseType.DataBase_Type.MySql.toString().equals(dbType)){
			return new Sql(new FieldMysql().get(table));
		}else{
			throw new ErrorMessage("Database type is not found:"+dbType+"!");
		}
		
	}
	
	/**
	 * 取建主键sql
	 * @return 建主键sql
	 * @throws ErrorMessage 
	 */
	public Sql getPk() throws ErrorMessage{
		if(DatabaseType.DataBase_Type.Oracle.toString().equals(dbType)){
			return new Sql(new PkOracle().get(table));
		}else if(DatabaseType.DataBase_Type.Db2.toString().equals(dbType)){
			return new Sql(new PkDb2().get(table));
		}else if(DatabaseType.DataBase_Type.Sybase.toString().equals(dbType)){
			return new Sql(new PkSybase().get(table));
		}else if(DatabaseType.DataBase_Type.SqlServer.toString().equals(dbType)){
			return new Sql(new PkSqlServer().get(table));
		}else if(DatabaseType.DataBase_Type.Informax.toString().equals(dbType)){
			return new Sql(new PkInformax().get(table));
		}else if(DatabaseType.DataBase_Type.Derby.toString().equals(dbType)){
			return new Sql(new PkDerby().get(table));
		}else if(DatabaseType.DataBase_Type.MySql.toString().equals(dbType)){
			return new Sql(new PkMySql().get(table));
		}else{
			throw new ErrorMessage("Database type is not found:"+dbType+"!");
		}
		
	}
	
	/**
	 * 取建外键sql
	 * @return 建外键sql
	 * @throws ErrorMessage 
	 */
	public Sql getFk() throws ErrorMessage{
		if(DatabaseType.DataBase_Type.Oracle.toString().equals(dbType)){
			return new Sql(new FkOracle().get(table));
		}else if(DatabaseType.DataBase_Type.Db2.toString().equals(dbType)){
			return new Sql(new FkDb2().get(table));
		}else if(DatabaseType.DataBase_Type.Sybase.toString().equals(dbType)){
			return new Sql(new FkSybase().get(table));
		}else if(DatabaseType.DataBase_Type.SqlServer.toString().equals(dbType)){
			return new Sql(new FkSqlServer().get(table));
		}else if(DatabaseType.DataBase_Type.Informax.toString().equals(dbType)){
			return new Sql(new FkInformax().get(table));
		}else if(DatabaseType.DataBase_Type.Derby.toString().equals(dbType)){
			return new Sql(new FkDerby().get(table));
		}else if(DatabaseType.DataBase_Type.MySql.toString().equals(dbType)){
			return new Sql(new FkMySql().get(table));
		}else{
			throw new ErrorMessage("Database type is not found:"+dbType+"!");
		}
		
	}
	
	/**
	 * 取建索引sql
	 * @return 建索引sql
	 * @throws ErrorMessage 
	 */
	public Sql getIndex() throws ErrorMessage{
		if(DatabaseType.DataBase_Type.Oracle.toString().equals(dbType)){
			return new Sql(new IndexOracle().get(table));
		}else if(DatabaseType.DataBase_Type.Db2.toString().equals(dbType)){
			return new Sql(new IndexDb2().get(table));
		}else if(DatabaseType.DataBase_Type.Sybase.toString().equals(dbType)){
			return new Sql(new IndexSybase().get(table));
		}else if(DatabaseType.DataBase_Type.SqlServer.toString().equals(dbType)){
			return new Sql(new IndexSqlServer().get(table));
		}else if(DatabaseType.DataBase_Type.Informax.toString().equals(dbType)){
			return new Sql(new IndexInformax().get(table));
		}else if(DatabaseType.DataBase_Type.Derby.toString().equals(dbType)){
			return new Sql(new IndexDerby().get(table));
		}else if(DatabaseType.DataBase_Type.MySql.toString().equals(dbType)){
			return new Sql(new IndexMySql().get(table));
		}else{
			throw new ErrorMessage("Database type is not found:"+dbType+"!");
		}
		
	}
	
	/**
	 * 取建表sql
	 * @return 建表sql
	 * @throws ErrorMessage 
	 */
	public Sql getTableDrop() throws ErrorMessage{
		if(DatabaseType.DataBase_Type.Oracle.toString().equals(dbType)){
			return new Sql(new FieldOracle().getDrop(table));
		}else if(DatabaseType.DataBase_Type.Db2.toString().equals(dbType)){
			return new Sql(new FieldDb2().getDrop(table));
		}else if(DatabaseType.DataBase_Type.Sybase.toString().equals(dbType)){
			return new Sql(new FieldSybase().getDrop(table));
		}else if(DatabaseType.DataBase_Type.SqlServer.toString().equals(dbType)){
			return new Sql(new FieldSqlServer().getDrop(table));
		}else if(DatabaseType.DataBase_Type.Informax.toString().equals(dbType)){
			return new Sql(new FieldInformax().getDrop(table));
		}else if(DatabaseType.DataBase_Type.Derby.toString().equals(dbType)){
			return new Sql(new FieldDerby().getDrop(table));
		}else if(DatabaseType.DataBase_Type.MySql.toString().equals(dbType)){
			return new Sql(new FieldMysql().getDrop(table));
		}else{
			throw new ErrorMessage("Database type is not found:"+dbType+"!");
		}
		
	}
	
	/**
	 * 取建外键sql
	 * @return 建外键sql
	 * @throws ErrorMessage 
	 */
	public Sql getFkDrop() throws ErrorMessage{
		if(DatabaseType.DataBase_Type.Oracle.toString().equals(dbType)){
			return new Sql(new FkOracle().getDrop(table));
		}else if(DatabaseType.DataBase_Type.Db2.toString().equals(dbType)){
			return new Sql(new FkDb2().getDrop(table));
		}else if(DatabaseType.DataBase_Type.Sybase.toString().equals(dbType)){
			return new Sql(new FkSybase().getDrop(table));
		}else if(DatabaseType.DataBase_Type.SqlServer.toString().equals(dbType)){
			return new Sql(new FkSqlServer().getDrop(table));
		}else if(DatabaseType.DataBase_Type.Informax.toString().equals(dbType)){
			return new Sql(new FkInformax().getDrop(table));
		}else if(DatabaseType.DataBase_Type.Derby.toString().equals(dbType)){
			return new Sql(new FkDerby().getDrop(table));
		}else if(DatabaseType.DataBase_Type.MySql.toString().equals(dbType)){
			return new Sql(new FkMySql().getDrop(table));
		}else{
			throw new ErrorMessage("Database type is not found:"+dbType+"!");
		}
		
	}
	
	
}
